<template>
  <div>
    <!-- 查询工具栏 -->
    <el-form :inline="true" :model="dataForm">
      <el-form-item label="卡号：">
        <el-input v-model="dataForm.cardNo" placeholder="卡号" readonly></el-input>
      </el-form-item>
      <el-form-item label="时间：">
        <el-date-picker
            v-model="dateTimeRange"
            end-placeholder="结束日期"
            range-separator="至"
            start-placeholder="开始日期"
            type="datetimerange">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button circle icon="el-icon-search" type="primary" @click="getDataList"></el-button>
      </el-form-item>
    </el-form>
    <!-- 数据列表 -->
    <el-table :data="dataList" border size="small" stripe style="width: 100%">
      <el-table-column align="center" label="#" type="index" width="50"></el-table-column>
      <el-table-column label="卡号" prop="cardNo"></el-table-column>
      <el-table-column label="消费金额" prop="amount"></el-table-column>
      <el-table-column label="本金扣款" prop="capitalAmount"></el-table-column>
      <el-table-column label="赠金扣款" prop="giftAmount"></el-table-column>
      <el-table-column label="消费油站" prop="consumptionStationName"></el-table-column>
      <el-table-column label="消费时间" prop="consumptionDate" show-overflow-tooltip></el-table-column>
      <el-table-column label="消费场景" prop="scene"></el-table-column>
      <el-table-column label="开卡油站" prop="cardStationName"></el-table-column>
    </el-table>
    <div class="pagination-container">
      <el-pagination :current-page="param.pageNum" :page-size="param.pageSize" :page-sizes="[10,20,30,50]"
                     :total="total" background layout="total, sizes, prev, pager, next, jumper"
                     @size-change="handleSizeChange" @current-change="handleCurrentChange"/>
    </div>
  </div>
</template>
<script>
import moment from 'moment'
import {getCardConsumptionList} from '@/api/card'

export default {
  name: 'CardConsumptionInfo',
  props: ['cardInfo'],
  data () {
    return {
      total: 0,
      param: {
        pageNum: 1,
        pageSize: 10,
        dataObj: {
          cardNo: '',
          consumptionDate1: '',
          consumptionDate2: ''
        }
      },
      dateTimeRange: [],
      dataForm: {
        masterUid: '',
        cardNo: '',
        startDate: '',
        endDate: ''
      },
      dataList: []
    }
  },
  mounted () {
    this.dateTimeRange.push(moment().subtract(7, 'days').startOf('day'))
    this.dateTimeRange.push(moment().endOf('day'))
  },
  methods: {
    getDataList () {
      this.param.dataObj.cardNo = this.dataForm.cardNo
      this.param.dataObj.consumptionDate1 = this.dateTimeRange[0]
      this.param.dataObj.consumptionDate2 = this.dateTimeRange[1]
      getCardConsumptionList(this.param).then(res => {
        console.log(res)
        this.dataList = res.data.records
        this.total = res.data.total
        this.$message.success('查询成功')
      }).catch(err => {
        console.log(err)
        this.$message.error(err || '查询失败！')
      })
    },
    handleSizeChange (size) {
      this.param.size = size
      this.getDataList()
    },
    handleCurrentChange (page) {
      this.param.page = page
      this.getDataList()
    }
  },
  watch: {
    cardInfo (newVal, oldVal) {
      console.log(newVal)
      this.dataForm.cardNo = newVal.cardNo
      this.dataForm.masterUid = newVal.masterUid
      if (!newVal.cardNo) {
        this.dataList = []
        this.total = 0
      }
    }
  }
}
</script>

<style scoped>
.pagination-container {
  margin-top: 10px;
}
</style>
